import React from 'react';
import styles from './index.less';
import { connect, Helmet } from 'umi';
import Chart from './Chart';
import Upload from './Upload';
import moment from 'moment';
import { vesselTest, vesselrReadTemplate } from '@/network/api/commonApi';

// 后端返回的数据结构
var dataObj = {
  vesselReference: 'APLYS13',
  vesselDirection: 0,
  craneWorkList: [
    {
      bay: 2,
      totalWiCount: 3,
      left: { bay: 1, totalWiCount: 0 },
      right: { bay: 3, totalWiCount: 2 },
      workQueueList: [
        {
          craneId: 'CR18',
          bay: 2,
          workInstructionCount: 3,
          startWorkTime: '2021-09-27 21:15:00',
          endWorkTime: '2021-09-27 22:00:00',
        },
      ],
    },
    {
      bay: 6,
      totalWiCount: 0,
      left: { bay: 5, totalWiCount: 0 },
      right: { bay: 7, totalWiCount: 0 },
      workQueueList: [],
    },
    {
      bay: 10,
      totalWiCount: 135,
      left: { bay: 9, totalWiCount: 74 },
      right: { bay: 11, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR18',
          bay: 10,
          workInstructionCount: 138,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 17:00:00',
        },
      ],
    },
    {
      bay: 14,
      totalWiCount: 44,
      left: { bay: 13, totalWiCount: 17 },
      right: { bay: 15, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR18',
          bay: 14,
          workInstructionCount: 44,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 16:43:00',
        },
      ],
    },
    {
      bay: 18,
      totalWiCount: 150,
      left: { bay: 17, totalWiCount: 0 },
      right: { bay: 19, totalWiCount: 52 },
      workQueueList: [
        {
          craneId: 'CR17',
          bay: 19,
          workInstructionCount: 150,
          startWorkTime: '2021-09-27 17:20:00',
          endWorkTime: '2021-09-27 21:40:00',
        },
      ],
    },
    {
      bay: 22,
      totalWiCount: 133,
      left: { bay: 21, totalWiCount: 0 },
      right: { bay: 23, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR17',
          bay: 22,
          workInstructionCount: 78,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 17:20:00',
        },
        {
          craneId: 'CR17',
          bay: 22,
          workInstructionCount: 55,
          startWorkTime: '2021-09-27 21:40:00',
          endWorkTime: '2021-09-28 00:17:00',
        },
      ],
    },
    {
      bay: 26,
      totalWiCount: 130,
      left: { bay: 25, totalWiCount: 0 },
      right: { bay: 27, totalWiCount: 4 },
      workQueueList: [
        {
          craneId: 'CR16',
          bay: 26,
          workInstructionCount: 91,
          startWorkTime: '2021-09-27 17:20:00',
          endWorkTime: '2021-09-27 21:40:00',
        },
        {
          craneId: 'CR16',
          bay: 26,
          workInstructionCount: 39,
          startWorkTime: '2021-09-28 03:20:00',
          endWorkTime: '2021-09-28 05:11:00',
        },
      ],
    },
    {
      bay: 30,
      totalWiCount: 175,
      left: { bay: 29, totalWiCount: 0 },
      right: { bay: 31, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR16',
          bay: 30,
          workInstructionCount: 56,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 17:20:00',
        },
        {
          craneId: 'CR16',
          bay: 30,
          workInstructionCount: 119,
          startWorkTime: '2021-09-27 21:40:00',
          endWorkTime: '2021-09-28 03:20:00',
        },
      ],
    },
    {
      bay: 34,
      totalWiCount: 34,
      left: { bay: 33, totalWiCount: 0 },
      right: { bay: 35, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR15',
          bay: 34,
          workInstructionCount: 34,
          startWorkTime: '2021-09-27 17:20:00',
          endWorkTime: '2021-09-27 18:56:00',
        },
      ],
    },
    {
      bay: 38,
      totalWiCount: 49,
      left: { bay: 37, totalWiCount: 0 },
      right: { bay: 39, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR15',
          bay: 38,
          workInstructionCount: 49,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 17:20:00',
        },
      ],
    },
    {
      bay: 42,
      totalWiCount: 102,
      left: { bay: 41, totalWiCount: 0 },
      right: { bay: 43, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR15',
          bay: 42,
          workInstructionCount: 102,
          startWorkTime: '2021-09-27 18:56:00',
          endWorkTime: '2021-09-27 23:32:00',
        },
      ],
    },
    {
      bay: 46,
      totalWiCount: 209,
      left: { bay: 45, totalWiCount: 0 },
      right: { bay: 47, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR14',
          bay: 46,
          workInstructionCount: 90,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 18:56:00',
        },
        {
          craneId: 'CR14',
          bay: 46,
          workInstructionCount: 119,
          startWorkTime: '2021-09-28 00:32:00',
          endWorkTime: '2021-09-28 06:11:00',
        },
      ],
    },
    {
      bay: 50,
      totalWiCount: 145,
      left: { bay: 49, totalWiCount: 0 },
      right: { bay: 51, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR14',
          bay: 50,
          workInstructionCount: 145,
          startWorkTime: '2021-09-27 18:56:00',
          endWorkTime: '2021-09-28 00:32:00',
        },
      ],
    },
    {
      bay: 54,
      totalWiCount: 212,
      left: { bay: 53, totalWiCount: 60 },
      right: { bay: 55, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR13',
          bay: 54,
          workInstructionCount: 113,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 18:56:00',
        },
        {
          craneId: 'CR13',
          bay: 54,
          workInstructionCount: 99,
          startWorkTime: '2021-09-28 02:51:00',
          endWorkTime: '2021-09-28 07:19:00',
        },
      ],
    },
    {
      bay: 58,
      totalWiCount: 181,
      left: { bay: 57, totalWiCount: 0 },
      right: { bay: 59, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR13',
          bay: 58,
          workInstructionCount: 181,
          startWorkTime: '2021-09-27 18:56:00',
          endWorkTime: '2021-09-28 02:51:00',
        },
      ],
    },
    {
      bay: 62,
      totalWiCount: 0,
      left: { bay: 61, totalWiCount: 0 },
      right: { bay: 63, totalWiCount: 0 },
      workQueueList: [],
    },
    {
      bay: 66,
      totalWiCount: 267,
      left: { bay: 65, totalWiCount: 48 },
      right: { bay: 67, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR12',
          bay: 66,
          workInstructionCount: 267,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-28 02:14:00',
        },
      ],
    },
    {
      bay: 70,
      totalWiCount: 0,
      left: { bay: 69, totalWiCount: 0 },
      right: { bay: 71, totalWiCount: 0 },
      workQueueList: [],
    },
    {
      bay: 74,
      totalWiCount: 110,
      left: { bay: 73, totalWiCount: 0 },
      right: { bay: 75, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR11',
          bay: 74,
          workInstructionCount: 110,
          startWorkTime: '2021-09-27 16:34:00',
          endWorkTime: '2021-09-27 21:49:00',
        },
      ],
    },
    {
      bay: 78,
      totalWiCount: 33,
      left: { bay: 77, totalWiCount: 0 },
      right: { bay: 79, totalWiCount: 0 },
      workQueueList: [
        {
          craneId: 'CR11',
          bay: 78,
          workInstructionCount: 33,
          startWorkTime: '2021-09-27 15:00:00',
          endWorkTime: '2021-09-27 16:34:00',
        },
      ],
    },
    {
      bay: 82,
      totalWiCount: 0,
      left: { bay: 81, totalWiCount: 0 },
      right: { bay: 83, totalWiCount: 0 },
      workQueueList: [],
    },
  ],
  bayList: null,
  vesselStartTime: '2021-09-27 15:00:00',
  vesselEndTime: '2021-09-28 23:00:00',
};
export default class extends React.Component {
  state = {
    data: null,
    init: false,
  };
  componentDidMount = async () => {
    this.init();
  };
  init = async () => {
    // this.setState({ init: false });
    // var rs = await vesselTest();
    // if (rs.code != 200) return;
    // var data = rs.result;
    // console.log(JSON.stringify(data));
    var data = dataObj;
    this.setState({ data: data, init: true });
  };
  setParent = obj => {
    this.setState(obj);
  };
  render() {
    const { data, init } = this.state;
    return (
      <div className={styles.container}>
        <Helmet>
          <title>甘特图</title>
        </Helmet>
        <div style={{ marginBottom: '20px' }}>
          <Upload setParent={this.setParent} init={this.init} />
        </div>
        {init && (
          <Chart
            data={data}
            colors={[
              '#AED7AB',
              '#F3DA5C',
              '#DF4416',
              '#729FC9',
              '#38B2E1',
              '#603891',
              '#F0B08A',
            ]}
          />
        )}
      </div>
    );
  }
}
